﻿using System.Net.Http;
using System.Threading.Tasks;

namespace ImoviesBlazorAntPro.Server.Helpers
{
    public static class HtmlUtils
    {
        /// <summary>
        /// 获取html源文本
        /// </summary>
        /// <returns></returns>
        public static async Task<string> GetHtmlTxt(string url)
        {
            //return await (new HttpClient()).GetStringAsync(url);
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36");
            //client.DefaultRequestHeaders.Add("Sec-Fetch-Site", "none");
            //client.DefaultRequestHeaders.Add("Sec-Fetch-Mode", "navigate");
            //client.DefaultRequestHeaders.Add("Sec-Fetch-Dest", "document");
            //client.DefaultRequestHeaders.Add("Sec-Fetch-User", "?1");
            client.DefaultRequestHeaders.Add("sec-ch-ua-platform", "\"Windows\"");
            return await client.GetStringAsync(url);
        }
    }
}
